﻿using System.Linq;

namespace TimetableCSP.Scheduler.Entities
{
	/// <summary>
	/// This constraint guarantees that no two classes are taught on the same classroom at the same time.
	/// </summary>
	public class ClassroomConstraint : BinaryConstraint
	{
		/// <summary>
		/// Determines whether there's a conflict between the two variables.
		/// </summary>
		/// <param name="a">The first variable.</param>
		/// <param name="b">The second variable.</param>
		/// <param name="conflictingAttributes">If there's a conflict, then this array holds the names of those attributes that need to be modified in order to solve the conflict.</param>
		/// <returns>
		///   <c>true</c> if there's a conflict; otherwise, <c>false</c>.
		/// </returns>
		public override bool IsConflict(AbstractVariable a, AbstractVariable b, out string[] conflictingAttributes)
		{
			conflictingAttributes = null;
			ClassVariable classA = (ClassVariable)a;
			ClassVariable classB = (ClassVariable)b;
			if (classA.Classroom == classB.Classroom && classA.Timeslot == classB.Timeslot)
			{
				conflictingAttributes = classA.GetAttributeNames().ToArray<string>();
				ConflictCount++;
				return true;
			}
			return false;
		}
	}
}
